<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目信息</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
 <div class="Wrapper">
        <div>
           <div id="pageInTab" class="pageInTab">
		   <div tabid="tabA" title="基本信息" lselected="true">
		<form id="fnc_prj_bsc_info_form" >
             <div class="fieldset1 tabel_col clearFix">
              <div class="fieldBox col_50">
                    <div class="label">项目名称</div>
                <div class="field">
                  <span id="fncprjnm" name="fncprjnm">&nbsp;${m.FNC_PRJ_NM}</span>
                </div>

             </div>
              <div class="fieldBox col_50">
                    <div class="label">还款期次</div>
                <div class="field">
                  <span id="payPd" name="payPd">&nbsp;${m.PAY_PD}</span>
                </div>

             </div>
             <div class="fieldBox col_50">
                <div class="label">金融机构</div>
                <div class="field">
                    <span id="fncinsNM" name="fncinsNM">&nbsp;${m.FUND_RAS_INS_NM}</span>
                </div>

             </div>
                             
             <div class="fieldBox col_50">
                    <div class="label">融资方案</div>
                <div class="field">
                   <span id="fncscmNM" name="fncscmNM">&nbsp;${m.FNC_SCM_NM}</span>
                </div>

             </div>
               <div class="fieldBox col_50">
                    <div class="label">归集日期</div>
                <div class="field">
                   <span id="gthrDt" name="gthrDt">&nbsp;${m.GTHR_DT}</span>
                </div>
               
             </div>
                      <div class="fieldBox col_50">
                    <div class="label">还款日期</div>
                <div class="field">
                   <span id="payDt" name="payDt">&nbsp;${m.PAY_DT}</span>
                </div>

             </div>
              <div class="fieldBox col_50">
                    <div class="label">超额抵押</div>
                <div class="field">
                   <span id="paidUpAmt" name="paidUpAmt">&nbsp;${m.PAID_UP_AMT}</span>
                </div>
               
             </div>
                      <div class="fieldBox col_50">
                    <div class="label">到账超额抵押</div>
                <div class="field">
                   <span id="surplusMoney" name="surplusMoney">&nbsp;${m.SURPLUS_MONEY}</span>
                </div>

             </div>
             
             <!-- [融资部融资组长审批]和[财务核实到账]节点，新增字段“历史退回金额”、“历史不可退回金额” -->
             <c:if test="${!from && from != 'creatorUpdate'}">
	             <div class="fieldBox col_50">
					<div class="label">历史退回金额</div>
	                <div class="field">
	                	<span id="hisTransAm" name="hisTransAm">&nbsp;${m.HIS_TRANS_AM}</span>
	                </div>
	             </div> 
	             <div class="fieldBox col_50">
					<div class="label">历史不可退回金额</div>
	                <div class="field">
	                	<span id="hisTransAccNoReturn" name="hisTransAccNoReturn">&nbsp;${m.HIS_TRANS_AM_NO_RETURN}</span>
	                </div>
	             </div> 
             </c:if>
         
              <div class="fieldBox col_50">
                    <div class="label">到账日期</div>
                <div class="field">
                    <input name="transTm" id="transTm" type="text"  class="ui-datepicker" value="${m.TRANS_TM}"  
                    				 validate="{required:true}">
                </div>
             </div>       
                <div class="fieldBox col_50">
                    <div class="label">退回金额</div>
                <div class="field">
                 <input name="transAm" id="transAm" type="text" class="ui-textbox"  <c:if test="${!from && from != 'creatorUpdate'}">readonly="readonly" </c:if> 
                 				value="${m.TRANS_AM}" validate="{number:true,required:true}" >
                </div>
                <div style="display: none">
                </div>
             </div> 
              <div class="fieldBox col_50">
                    <div class="label">不可退回金额</div>
                <div class="field">
                 <input name="transAccNoReturn" id="transAmNoReturn" type="text" class="ui-textbox"  <c:if test="${!from && from != 'creatorUpdate'}">readonly="readonly" </c:if> 
                 			value="${m.TRANS_AM_NO_RETURN}"   validate="{number:true,required:true}" >
                </div>
              
             </div> 
    
             
               <div class="fieldBox col_50">
                    <div class="label">收款账号 </div>
                <div class="field">
                   
                    <input name="accNo" id="accNo" type="text"   value="${m.ACC_NO}"  <c:if test="${!from}">readonly="readonly" </c:if>
                    			validate="{required:true}" >
                    <input name="transAcc" id="transAcc" type="hidden" class="ui-textbox" value="${m.TRANS_ACC}">
                    <c:if test="${from == 'creatorUpdate'}">
                 		<span id="chooseCst" class="sq-button sq-button-round"  onclick="choosePage()">选择账户</span>
                 		</c:if>
                </div>
                <div style="display: none">
                </div>
             </div>  
               <div class="fieldBox col_50">
                    <div class="label">收款银行</div>
                <div class="field">
                    <input name="transBank" id="transBank" type="text" class="ui-textbox" readonly="readonly" value="${m.TRANS_BANK}" validate="{required:true}" >
                </div>
                <div style="display: none">
                </div>
             </div>           
             
             <!-- [融资部融资组长审批]和[财务核实到账]节点，新增字段“当前盈余”=退回金额+历史退回金额-已付超额抵押 -->
             <c:if test="${!from && from != 'creatorUpdate'}">
				<div class="fieldBox col_50">
					<div class="label"><font color="red"><b>当前盈余</b></font></div>
	                <div class="field">
	                    <input id=surplus name="surplus" type="text" class="ui-textbox" readonly="readonly" validate="{required:true}" />
	                </div>
				</div>
             </c:if>
             
            </div>
            
            <c:if test="${from == 'creatorUpdate'}">
	   			<div class="btnsBox">
	               <span id="saveBtn" class="sq-button sq-button-round" onclick="save();">保存</span>
	            </div>
 			</c:if>

	         
         
        </form>
        </div>
             
        </div>
        </div>
    </div>
    
	<script type="text/javascript">
	  var pageInApp={
	    		flag:true
	    };
	  var id ='${id}';
	  var selectOrgCd = "";
	   var searchOrgTree = null;
	  var firstNode = null;
	  var textName='${orgTextName}';//节点名称
	  var orgData = null;
		var id ="";//初始值
		var detailFlag = '${detailFlag}';
		var isFlow = '${isFlow}';
	$(function () {
		initData();
		getSurplus();//计算当前盈余
	});
	
	//计算 当前盈余=退回金额+历史退回金额-已付超额抵押
	function getSurplus(){
		var transAm = (!"${m.TRANS_AM}")? 0 : new Number("${m.TRANS_AM}");
		var hisTransAm = (!"${m.HIS_TRANS_AM}")? 0 : new Number("${m.HIS_TRANS_AM}");
		var paidUpAmt = (!"${m.PAID_UP_AMT}")? 0 : new Number("${m.PAID_UP_AMT}");
		var surplus = 0;
		//if(transAm!='' && hisTransAm!='' && paidUpAmt!=''){
			surplus = parseFloat(transAm) + parseFloat(hisTransAm) - parseFloat(paidUpAmt);
		//}
		$("#surplus").val(surplus);
	}
	
	//初始化数据
	function initData(){

		 initTab();
			$("#fnc_prj_bsc_info_form").ligerForm({
			    validate: true
			});
			 var ligerForm = liger.get("fnc_prj_bsc_info_form");
		 $("#fnc_prj_bsc_info_form").check_ligerFormEditor();
		
		
	}
	var pageInTab = null;
	  var loadedTabs=[]
	
	//初始化Tab
    function initTab(){
    	 pageInTab = $("#pageInTab").ligerTab({
             height: 'auto',
             contextmenu: false,
             minIframeHeight: GET_minIframeHeight(),
             onBeforeSelectTabItem: function (tabid) {
             	var id = $("#prjid").val();
             		//alert("id="+id);
             	 if(tabid!="tabA"){
 	             	if(id==null||id==''){
 	                	top.$.ligerDialog.SQalert({content:"请先保存项目基本信息", SQ_type: "warning"});
 	                	return false;
 	                } 
             	} 
             },
             onAfterSelectTabItem: function(tabid) {
              //   if (loadedTabs.indexOf(tabid)<0) {
                 	var id = $("#prjid").val();
                 	//alert("id="+id);
                 	 if(tabid!="tabA"){
 	                	if(id==null||id==''){
 	                		 top.$.ligerDialog.SQalert({content: LogUtils.LOG_PRJ__PRD_SELECT_BEFORE, SQ_type: "warning"});
 	                         return false; //验证不通过，不执行以下代码
 	                	}
                 	} 
                     loadedTabs.push(tabid);

            //     };
                 SetIframe_height();
             }
         });

         $.extend(true, pageInApp, {
             pageInTab: pageInTab
         });
    };
	//保存项目基础信息
	function save(){
        var ligerForm = liger.get("fnc_prj_bsc_info_form");
        if (!ligerForm.valid()) {
            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
            return false; //验证不通过，不执行以下代码
        }
                   var paidUpAmt=new Number("${m.PAID_UP_AMT}");//超额抵押
                   var surplusMoney =new Number("${m.SURPLUS_MONEY}");//到账超额抵押
                   var transAm =new Number($("#transAm").val());//退回金额
                   var transAmNoReturn =new Number($("#transAmNoReturn").val());//不可退回金额
                   
                   if(paidUpAmt<(surplusMoney+transAm + transAmNoReturn)){
                	   top.$.ligerDialog.SQalert({content:"超额抵押不能大于(到账超额抵押+退回金额+不可退回金额),超额抵押:"
                		   +paidUpAmt+" (到账超额抵押+退回金额+不可退回金额)："+(surplusMoney+transAm + transAmNoReturn),SQ_type: "warning"});
                       return false;   
                   }
                   console.log("paidUpAmt:"+paidUpAmt + "  (surplusMoney+transAm + transAmNoReturn):"+(surplusMoney+transAm + transAmNoReturn));
                   
                 
	    				  var data = ligerForm.getData();
	    			      
	    			       
	    			       data["id"]="${m.ID}";
	    			       data["transAcc"]= $("#accNo").val();
	    			       data["transAm"]=  accMul(transAm,100);
	    			       data["transAccNoReturn"]=   accMul(transAmNoReturn,100);
	    			       
	    			     

	    			       console.log("data:"+JSON.stringify(data));
	    			      // return ;
	    			       
	    			        var url = '<%=path%>/rfbuss/fnovercollinfo/modify.do';

	    			        var wait_dialog;
	    			        $.ajax({
	    			    		type: 'post',
	    			    		dataType:'json',
	    			    		data:data,
	    			    		url: url,
	    			    		beforeSend: function(){
	    					          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	    					     },
	    			    		success:function(msg){
	    			    			 wait_dialog.close();
	    			    			 if(msg.success == 1){
	    			    					 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	    			    			 }else{
	    			    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			    			 }
	    			    		},error:function (XMLHttpRequest, textStatus, errorThrown) { 
	    							wait_dialog.close();
	    							$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
	    						} 
	    			    	});
     	    	
	}

	  //js 乘法函数  
	   //调用：accMul(arg1,arg2)   
	   //返回值：arg1乘以arg2的精确结果   
	   function accMul(arg1,arg2)   
	   {   
	     var m=0,s1=arg1.toString(),s2=arg2.toString();   
	     try{m+=s1.split(".")[1].length}catch(e){}   
	     try{m+=s2.split(".")[1].length}catch(e){}   
	     return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)   
	   }  
	  
	//选择页面
	function choosePage(){
	
        $.ligerDialog.open({  title: '选择账户',height: 500,width: 850, url: '<%=path%>/rfbuss/fncprjbscinfo/toChooseCompAccPage.do?flag=ocr'});
	}
	 
	  function initPayList(){
	   	   var instid = $("#fncInsId").val();
	   	   
	   	  var combobox= $("#transAcc").ligerComboBox({
	             columns: [
	 		            /* { header: '账户类型', name: 'accTypNm', width: 100},  */
	 	                { header: '开户行名', name: 'bkNm', width: 100}, 
	 	                { header: '账户名称', name: 'accNm', width: 120},
	 	                { header: '账号', name: 'accNo', width: 120},
	 		            /* { header: '账户ID', name: 'id'}, */
	 	               ],
	 	            url:'<%=path%>/rfbase/fncprjfstpyinfo/initPayList.do?insId='+instid,
	 	            ajaxType :'GET',
	 	            width: 300, 
	 	            slide: false,
	 	            selectBoxWidth: 1880, 
	 	            selectBoxHeight: 740,
	 	            valueField: 'id', 
	 	            textField: 'accNo',
	 	           onSelected: function ()
	 	             {
	 	        	  var obj=combobox.getSelected();
	 	        	    $("#transBank").val(obj.bkNm);
	 	        	   
	 	             }
	 	       });
	   	liger.get("transAcc").selectValue("${focvo.transAcc}"); 
	     }
    </script>

</body>
</html>